package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.puruo.mindhall.utils.PageUtil;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import com.puruo.mindhall.bean.Result;
import com.puruo.mindhall.bean.PageInfo;
import java.math.BigDecimal;
import com.puruo.mindhall.service.GiHallMybatisService;
/**
* <p>
* ${table.comment} 前端控制器
* </p>
* @author ${author}
* @since ${date}
*/
@Controller
@RequestMapping("/admin/${table.entityPath}/*")
public class ${table.controllerName} {

	@Autowired
	private ${table.serviceName} ${table.entityPath}Service;

	@Autowired
	private GiHallMybatisService giHallMybatisService;
<#list table.fields as field>
<#if field.keyFlag>
	/**
	* @Description: ${table.comment}详情
	* @author ${author}
	* @date ${date}
	* @return
	*/
	@GetMapping("/getById.do")
	@ResponseBody
	public Result getById(@RequestParam("id") <#if field.propertyType == "BigDecimal">Long</#if><#if field.propertyType != "BigDecimal">${field.propertyType}</#if>  id ) {
		if(id==null){
			return Result.error("参数不能为空");
		}
		return Result.success(${table.entityPath}Service.getById(id));
	}
</#if>
</#list>

	/**
	* @Description: ${table.comment}新增
	* @author ${author}
	* @date ${date}
	* @return
	*/
	@PostMapping(value = "/addModel.do")
	@ResponseBody
	public Result addModel(@RequestBody ${entity} param) {
		try {
			int count = ${table.entityPath}Service.insertBySelective(param);
			if (count > 0) {
				return Result.success();
			} else {
				return Result.error("新增信息失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error();
		}
	}

	/**
	* @Description: ${table.comment}修改
	* @author ${author}
	* @date ${date}
	* @return
	*/
	@PostMapping(value = "/updateModel.do")
	@ResponseBody
	public Result updateModel(@RequestBody ${entity} param) {
		try {
			int count = ${table.entityPath}Service.updateBySelective(param);
			if (count > 0) {
				return Result.success();
			} else {
				return Result.error("修改信息失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error();
		}
	}
<#list table.fields as field>
<#if field.keyFlag>
	/**
	* @Description: ${table.comment}删除
	* @author ${author}
	* @date ${date}
	* @return
	*/
	@PostMapping("deleteModel.do")
	@ResponseBody
	public Result deleteModel(@RequestParam("id") <#if field.propertyType == "BigDecimal">Long</#if><#if field.propertyType != "BigDecimal">${field.propertyType}</#if> id) {
		try {
			int count = ${table.entityPath}Service.deleteById(id);
			if (count > 0) {
				return Result.success();
		} else {
				return Result.error("刪除信息失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error();
		}
	}
</#if>
</#list>

	/**
	* @Description: 分页查询
	* @author ${author}
	* @date ${date}
	* @return
	*/
	@PostMapping("/pageList.do")
	@ResponseBody
	public  Result pageList(@RequestBody ${entity} params)  {
    params.setCurrentPage(PageUtil.getCurrentPage(params.getPage(),params.getLimit()));
	PageInfo<${entity}> pageInfo = ${table.entityPath}Service.getPage(params);
	return Result.success(pageInfo);
	}
}
